package com.mf.dispatcher;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import com.alibaba.fastjson.JSON;
import com.mf.controller.FileController;
import com.mf.entity.Msg;


@WebServlet("/FileDispatcher/*")
public class FileDispatcher extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private String traget;
	FileController fileController=new FileController();
	
    public FileDispatcher() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String url= request.getRequestURI();
		String myUrl = url.substring(url.lastIndexOf("/")+1);
		response.setContentType("application/json; charset=utf-8"); 
		PrintWriter out=response.getWriter();
		
		switch(myUrl){

		case "upload":
			String jsonString=JSON.toJSONString(fileController.fileUpload(request, response));
			traget = jsonString;
			System.out.println(jsonString);
			out=response.getWriter();
			out.println(traget);
			break;
		case "download":
			break;
		}
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
